import { useSelector } from 'react-redux'
import { StateType } from '../store'
import { ComponentsStateType } from '../store/componentsReducer'

// useSelector 从redux中获取。
// state是默认传入的store
function useGetComponentInfo() {
    // redux store中的全部数据 【redux禁止获取全部数据，控制台会报错】
    // const storeData = useSelector<StateType>(state => state)

    // 获取组件信息数据
    const components = useSelector<StateType>(
        state => state.components.present
    ) as ComponentsStateType

    // 解构
    const { componentsList = [], selectedId, copiedComponent } = components

    // 获取选中的组件信息
    const selectedComponent = componentsList.find(c => c.fe_id === selectedId)

    return {
        componentsList,
        selectedId,
        selectedComponent,
        copiedComponent,
        // storeData,
    }
}
export default useGetComponentInfo
